package com.lanou.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou.bean.Area;
import com.lanou.bean.City;
import com.lanou.bean.Province;
import com.lanou.mapper.AreaMapper;
import com.lanou.mapper.CityMapper;
import com.lanou.mapper.ProvinceMapper;
import com.lanou.service.Pcaservice;
import com.lanou.utils.AjaxResult;
import com.lanou.utils.MsgResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author 王远航
 * @date 18/3/10
 */
@Service
public class PcaServiceImpl implements Pcaservice {
    /**
     * 初始化列表
     */
    @Resource
    private AreaMapper areaMapper;
    @Resource
    private ProvinceMapper provinceMapper;
    @Resource
    private CityMapper cityMapper;

    AjaxResult ajaxResult = null;
    /**
     * 对省市区三级联动
     * @param cityId
     * @return AjaxResult
     * @author 王远航
     */

    @Override
    public AjaxResult getAreaDate(Integer cityId) {
        List<HashMap<Integer, Object>> list = areaMapper.selectAreaByCityId(cityId);
        return MsgResult.msgSuccess(list);
    }
    @Override
    public AjaxResult getCityData(Integer provinceId) {
        List<City> cityList = cityMapper.findCityByProvinceId(provinceId);
        return MsgResult.msgSuccess(cityList);
    }
    @Override
    public AjaxResult getAllProvinceData() {
        List<Province> provinceList = provinceMapper.selectAllProvince();
        return MsgResult.msgSuccess(provinceList);
    }
    @Override
    public AjaxResult getFourAreaDate(Integer cityId) {
        List<Area> areaList = areaMapper.selectAreaBycityId(cityId);
        return MsgResult.msgSuccess(areaList);
    }
}
